<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
model('core/wxwork_app')->checkauth('jy_merchscrm');
model('jy_scrm/model')->check_custom();
model('jy_scrm/model')->check_worker('',true);
if(!$_SESSION['wxworkapp_id']){
	$pid=pdo_getcolumn('core_plugins',array('name'=>'jy_merchscrm'),'id');
	$_SESSION['wxworkapp_id']=pdo_getcolumn('core_account_wxwork_app',array('pid'=>$pid,'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']),'id');
	if(!$_SESSION['wxworkapp_id']){
		$_SESSION['wxworkapp_id']=-1;
	}
}
//注册电商客会员
//$_SESSION['workeruserid']='cosen';
$item=pdo_get('jy_scrm_worker',array('merchid'=>$_SESSION['onemerchid'],'userid'=>$_SESSION['workeruserid'],'uniacid'=>$_SESSION['uniacid']));
if($_SESSION['container']=='wxwork' && !$item['avatar']){
	$return['show_wxworkmember']=2;
}
$item['mymembernum']=pdo_count('jy_scrm_member',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'follow_user_userid'=>$_SESSION['workeruserid']));
$item['myqunnum']=pdo_count('jy_scrm_qun',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'owner'=>$_SESSION['workeruserid']));
$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
$item['daymembernum']=pdo_count('jy_scrm_member',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'follow_user_userid'=>$_SESSION['workeruserid'],'createtime >'=>$daytime));
$item['daygenjinnum']=pdo_count('jy_scrm_worker_linelog',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'workerid'=>$item['id'],'createtime >'=>$daytime));
$item['genjinnum']=pdo_count('jy_scrm_worker_linelog',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'workerid'=>$item['id']));
$link_time[0]=0;
$link_time[1]=$daytime-3*24*3600;
$link_time[2]=$daytime-7*24*3600;
$link_time[3]=$daytime-15*24*3600;
$link_time[4]=$daytime-30*24*3600;
$link_time[5]=$daytime-90*24*3600;
$link_time[6]=$daytime-180*24*3600;
$link_times=$this->link_times;
$statuslist=array();
$buystatus=$this->user_buystatus;
foreach($buystatus as $k=>$v){
	$statuslist[$k]['title']=$v;
	$statuslist[$k]['num']=pdo_count('jy_scrm_member',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'follow_user_userid'=>$_SESSION['workeruserid'],'buystatus'=>$k));
	foreach($link_times as $lk=>$lv){
		$statuslist[$k]['list'][$lk]['title']=$lv;
		$statuslist[$k]['list'][$lk]['num']=pdo_count('jy_scrm_member',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'follow_user_userid'=>$_SESSION['workeruserid'],'buystatus'=>$k,'link_time <='=>$link_time[$lk]));
	}
}
$return['item']=$item;
$return['statuslist']=$statuslist;
$return['buystatus']=0;
set_html('title','会员中心');
exi($return);	
?>